package com.weipai.springboot.module.service.impl;

import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.mapper.CustomerMapper;
import com.weipai.springboot.module.mapper.GoodsMapper;
import com.weipai.springboot.module.mapper.OrderMapper;
import com.weipai.springboot.module.mapper.ShopMapper;
import com.weipai.springboot.module.service.ExternalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ${lyh}
 *
 * * 对外接口
 *
 * on 2018/11/16.
 */

@Service
public class ExternalServiceImpl implements ExternalService{


    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    ShopMapper shopMapper;
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    OrderMapper orderMapper;


    // 对外接口  返还商品的信息
    @Override
    public Response getGoodsMessage() {
        Response response = new Response();
        List<Map<String,Object>>  mapList = goodsMapper.getGoodsMessage();
        if (mapList.size() > 0) {
            response.setCode(RetCode.SUCCESS);
            response.setData(mapList);
        } else {
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }


    //对外接口  返回供应商信息
    @Override
    public Response getShopMessage() {
        Response response = new Response();
        List<Map<String,Object>>  mapList = shopMapper.getShopMessage();
        if (mapList.size() > 0) {
            response.setCode(RetCode.SUCCESS);
            response.setData(mapList);
        } else {
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }


    //对外接口  返回用户信息
    @Override
    public Response getCustomerMessage() {
        Response response = new Response();
        List<Map<String,Object>>  mapList = customerMapper.getCustomerMessage();
        if (mapList.size() > 0) {
            response.setCode(RetCode.SUCCESS);
            response.setData(mapList);
        } else {
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }

    //对外接口  返回客户订单信息
    @Override
    public Response getOrderMessage() {
        Response response = new Response();
        List<Map<String,Object>>  mapList = orderMapper.getOrderMessage();
        if (mapList.size() > 0) {
            response.setCode(RetCode.SUCCESS);
            response.setData(mapList);
        } else {
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }


    //对外接口 返还缺货预警信息
    @Override
    public Response getWarningGoods() {
        return null;
    }


}
